/* Copyright 2009 Sony Mathew, Minneapolis MN. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package com.xsm.lite.util;

/**
 * Provides default behaviour for logging, extend and override to use other logging utilities.
 *  
 * @author Sony Mathew
 */
public class Logg {

    protected final String header;
    
    /**
     * Obtain an instance of the Logg for the given header.
     * Change this method to use a new utlity for logging.
     * 
     * author Sony Mathew
     */
    public static Logg getLogg(String header) {
        return new Logg(header);
    }
    
    /**
     * Provide the header for this log.
     */
    protected Logg(String header) {
        this.header = header;
    }
    
    /**
     * Override for your needs. 
     */    
    public void debug(String msg) {
        out("DEBUG", msg, null); 
    }

    /**
     * Override for your needs. 
     */        
    public void info(String msg) {
        out("INFO", msg, null);
    }
    
    /**
     * Override for your needs. 
     */        
    public void warn(String msg, Throwable x) {
        out("WARN", msg, x);
    }
    
    /**
     * Override for your needs. 
     */        
    public void error(String msg, Throwable x) {
        out("ERROR", msg, x);
    }

    /**
     * Override for your needs. 
     */            
    protected void out(String level, String msg, Throwable x) {
        System.out.println(header + ":" + level + ": " + msg);
        if (x != null) {
            x.printStackTrace();
        }
    }
    
}
